home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / packet / p_tapr / tnchst / ax25.c < prev    next >
Text File  |  1990-06-04  |  4KB  |  195 lines

  1. /*** display function for aft test ****/
  2.  
  3. #define   AX25_ADDRLEN   7
  4.  
  5.  
  6. void moncall( callptr )
  7. byte *callptr;
  8. {
  9.     int x;
  10.  
  11.  
  12.     /* display callsign */
  13.  
  14.      for ( x = 0 ; x < AX25_ADDRLEN-1 ; ++x )
  15.         printf("%c", (*callptr++) >> 1 );
  16. }
  17.  
  18. void monframe( ptr, len )
  19. byte *ptr;            /* points to 1st byte of aft frame */
  20. int len;            /* length */
  21. {
  22.     putchar('\n');
  23.     moncall( ptr+AX25_ADDRLEN );    /* source call */
  24.     putchar('>');
  25.     moncall( ptr );        /* dest */
  26.     len -= (AX25_ADDRLEN * 2);
  27.     ptr += (AX25_ADDRLEN * 2);
  28.  
  29.     while ( (*(ptr-1) & 1) == 0 &&    /* do while all calls not displayed */
  30.         len > 0 )        /* and length is gt 0 in case not
  31.                        ax25 */
  32.      {
  33.         moncall( ptr ) ;    /* display a callsign */
  34.         putchar(',');
  35.         ptr += AX25_ADDRLEN ;        /* point to next callsign */
  36.         len -= AX25_ADDRLEN;
  37.     };
  38.     putchar(':');
  39.  
  40.     /** pointer is now pointing to cmd byte **/
  41.     if ( *ptr == 03 || (*ptr & 1) == 0 )    /** if unproto or info **/
  42.     {
  43.         len -= 2 ;            /** adj len for cmd & pid **/
  44.         ptr += 2 ;
  45.         while ( len-- > 0 )        /** while chars to display **/
  46.         {
  47.             if (*ptr == 0x0d )
  48.                 putchar('\n');    /* map cr's to newlines */
  49.             else
  50.                 putchar( *ptr );    /** print !cr's **/
  51.             ++ptr;
  52.         }
  53.     }
  54.     else /* else not data packet */
  55.         printf("cmd: %02X",*ptr);
  56.  
  57.     putchar('\n');
  58.  
  59. }
  60.  
  61.  
  62.  
  63. /**** aux routines from loh ****/
  64. makupper(c)
  65. char *c;
  66. {
  67.     *c = toupper( *c );
  68. }
  69.  
  70.  
  71. iswhite( c )
  72. char c;
  73. {
  74.     static word result ;
  75.  
  76.     switch ( c )
  77.     {
  78.         case ' ':
  79.         case ',':
  80.         case '\n':
  81.         case '\r':
  82.         case NULL:
  83.             result = TRUE  ; break ;
  84.         default:
  85.             result = FALSE ;
  86.     }
  87.     return result ;
  88. }
  89.  
  90. byte *atocall( buffer , chr )/* converts text callsign pointed to and returns
  91.                pointer to char AFTER last ssid char if
  92.                call was okay */
  93. byte    *buffer;
  94. char    *chr;
  95. {
  96.     int    is_ok ;
  97.         /* set to FALSE when bad call character encountered */
  98.     int    len   ;    /* # chars allowed in "text" portion */
  99.     char    *wk   ; /* work pointer */
  100.     int    ssid  ; /* hold ssid here when it is called for */
  101.  
  102.     is_ok = TRUE ;    /* assume okay */
  103.     len   = AX25_ADDRLEN - 1 ;    /* init with # of characters allowed*/
  104.  
  105.     wk = buffer ;        /* set up build ptr */
  106.  
  107.     while (is_ok && *chr && len)/* while more chars to cvt & len valid */
  108.     {
  109.      if ( *chr == '-' || iswhite( *chr ) )
  110.         break ;            /*white space or hyphen here?*/
  111.  
  112.      makupper( chr );
  113.  
  114.      if (   *chr >= 'A' && *chr <='Z' || isdigit( *chr ) )
  115.                  /* if valid */
  116.      {
  117.         *wk++ = *chr++ << 1 ;        /* move call */
  118.      }
  119.      else            /* else not valid char */
  120.         is_ok = FALSE ;    /* turn bad flag on */
  121.      end_if
  122.      --len ;    /* count a shifted character */
  123.     } /*endwhile*/
  124.  
  125.     if ( !is_ok || len == AX25_ADDRLEN - 1 )
  126.             /* if not ok or nothing converted or 6 chars cnvtd */
  127.         return  FALSE     ;    /* return if was bad */
  128.  
  129.     /* else valid up till now, perhaps there is also an
  130.        ssid.  first get the ssid (if any), then pad the
  131.        built callsign if that is needed */
  132.  
  133.     ssid = 0x60 ;    /* assume null ssid */
  134.       switch ( *chr++ )    /* if hyphen indicates ssid then */
  135.       { case '-':
  136.         if ( !isdigit( *chr ) )
  137.             is_ok = FALSE ;
  138.         else
  139.         {
  140.               ssid = *chr++ & 15 ; /*** 0-9 ssid only!! ***/
  141.             if ( isdigit( *chr ) )
  142.             {
  143.                 ssid *= 10 ;
  144.                 ssid += *chr++ & 15 ;
  145.             }
  146.             is_ok = ( ssid <<= 1 ) < 32 ;    /* validate ssid */
  147.             ssid |= 0x60 ;
  148.         }
  149.           break;
  150.         case NULL:
  151.         --chr; break;
  152.         default:
  153.         if ( !iswhite( *--chr ) )    /* garbage here after call */
  154.             is_ok = FALSE ;    /* else set error cuz no hyphen
  155.                        yet more */
  156.         else ;     /* else its whitespace and can continue or end */
  157.       } /* end switch */
  158.  
  159.         /* pad */
  160.     while ( len-- )    /* while there are empty spots in call */
  161.         *wk++ = ' ' << 1 ;
  162.  
  163.     *wk++ = ssid ;    /* write ssid byte, no E set */
  164.  
  165.     *wk++ = NULL ;
  166.  
  167.     return    ( is_ok ? chr : FALSE ); /* return with ptr to nx call or
  168.                         NIL if error */
  169. }
  170.  
  171.  
  172. char *calltoa( buffer , call ) /* convert call to ascii, result to buffer */
  173. byte *buffer;
  174. char *call;    /* char after ssid pointed to in return arg */
  175. {
  176.     register int    i ;
  177.     char *pssid;
  178.  
  179.     pssid = call + AX25_ADDRLEN - 1 ;    /* pointer to ssid byte */
  180.  
  181.     i = 0 ;
  182.  
  183.     while ( i++ < AX25_ADDRLEN-1 && *call != ' ' << 1 )
  184.         *buffer++ = *call++ >> 1 ;
  185.  
  186.     if ( i =  *pssid >> 1 & 15 ) /* if ssid != 0 */
  187.         sprintf( buffer , "-%d" , i ) ;
  188.     else
  189.         *buffer = NULL ;    /* else put null here */
  190.     end_if
  191.  
  192.     return ( pssid + 1 );
  193. }
  194.  
  195.